package megrez.common.core.util;

import lombok.experimental.UtilityClass;

/**
 * 操作系统工具
 *  
 * @author Lucky Yang
 * @since 0.0.1
 */
@UtilityClass
public class OsHelper {
    public enum OsType {
        /** 微软系统 */
        WINDOWS,
        /** 苹果系统 */
        MAC,
        /** Unix 或者Linux */
        LINUX,
        /** SUN */
        SOLARIS,
        /** 未知 */
        UNKNOW;

        @SuppressWarnings("all")
        public static OsType of(String osName) {
            if (OS_NAME.indexOf("win") >= 0) {
                return OsType.WINDOWS;
            } else if (OS_NAME.indexOf("mac") >= 0) {
                return OsType.MAC;
            } else if (OS_NAME.indexOf("nux") >= 0) {
                return OsType.LINUX;
            } else if (OS_NAME.indexOf("sunos") >= 0) {
                return OsType.SOLARIS;
            } else {
                return OsType.UNKNOW;
            }
        }
    }

    public static final String OS_NAME = System.getProperty("os.name").toLowerCase();
    public static final OsType OS = OsType.of(OS_NAME);

    public String getSystemProperties() {
        StringBuilder sb = new StringBuilder();
        System.getProperties().forEach((s1, s2) -> sb.append(s1 + " - " + s2));
        return sb.toString();
    } 
}
